package com.yuhang.learnandroid.dummy

import java.util.ArrayList
import java.util.HashMap

/**
 * Helper class for providing sample content for user interfaces created by
 * Android template wizards.
 *
 * TODO: Replace all uses of this class before publishing your app.
 */
object DummyContent {

    /**
     * An array of sample (dummy) items.
     */
    val ITEMS: MutableList<DummyItem> = ArrayList()

    /**
     * A map of sample (dummy) items, by ID.
     */
    val ITEM_MAP: MutableMap<String, DummyItem> = HashMap()

    private val COUNT = 25

    init {
        addItem(createDummyItem("GeoQuiz", "第一章"))
        addItem(createDummyItem("GeoQuiz2", "第二章"))
        addItem(createDummyItem("GeoQuiz5", "第五章"))
        addItem(createDummyItem("Crime", "第七章"))
        // Add some sample items.
        for (i in 1..COUNT) {
            addItem(createDummyItem("${i}"))
        }
    }

    private fun addItem(item: DummyItem) {
        ITEMS.add(item)
        ITEM_MAP.put(item.id, item)
    }

    private fun createDummyItem(itemName: String): DummyItem {
        return createDummyItem(itemName, makeDetails(itemName))
    }

    private fun createDummyItem(itemName: String, desc: String): DummyItem {
        return DummyItem(itemName, desc, desc)
    }

    private fun makeDetails(position: String): String {
        val builder = StringBuilder()
        builder.append("Details about Item: ${position}")
        return builder.toString()
    }

    /**
     * A dummy item representing a piece of content.
     */
    data class DummyItem(val id: String, val content: String, val details: String) {
        override fun toString(): String = content
    }
}
